import clientRequest from "@/utils/client-request.ts";

export function getSmsCodeApi(phone:string) {
    return clientRequest({
        url: "/user/sms/login",
        method: "get",
        params: {
            'phone': phone
        }
    })
}

export function smsCodeLoginApi(phone:string, smsCode:string) {
    return clientRequest({
        url: "/user/sms/login",
        method: "post",
        data: {
            'phone': phone,
            'smsCode': smsCode
        }
    })
}

export function logoutApi() {
    return clientRequest({
        url: "/user/logout",
        method: "delete",
    })
}

export function passwordLoginApi(phone:string, password:string) {
    return clientRequest({
        url: "/user/password/login",
        method: "post",
        data: {
            'phone': phone,
            'password': password
        }
    })
}

export function getUserDetailApi() {
    return clientRequest({
        url: "/user/info",
        method: "get",
    })
}

export function sendCodeToOldPhoneApi(phone:string) {
    return clientRequest({
        url: "/user/info/sms/old/" + phone,
        method: "get"
    })
}

export function verifyOldPhoneApi(phone:string, code:string) {
    return clientRequest({
        url: "/user/info/sms/old/verify",
        method: "post",
        data: {
            'phone': phone,
            'code': code
        }
    })
}

export function sendCodeToNewPhoneApi(phone:string) {
    return clientRequest({
        url: "/user/info/sms/new/" + phone,
        method: "get"
    })
}

export function verifyNewPhoneApi(phone:string, code:string) {
    return clientRequest({
        url: "/user/info/sms/new/verify",
        method: "post",
        data: {
            'phone': phone,
            'code': code
        }
    })
}

export function sendCodeToUpdatePasswordApi(phone:string) {
    return clientRequest({
        url: "/user/info/password/" + phone,
        method: "get"
    })
}

export function updatePasswordApi(phone:string, code:string, password:string, passwordRepeat:string) {
    return clientRequest({
        url: "/user/info/password",
        method: "post",
        data: {
            'phone': phone,
            'code': code,
            'password': password,
            'passwordRepeat': passwordRepeat
        }
    })
}

export function updateUserInfoApi(username: string) {
    return clientRequest({
        url: '/user/info',
        method: 'put',
        data: {
            'username': username
        }
    })
}

